package com.jw.blog.wblog.controller;


import com.jw.blog.wblog.entity.BlogType;
import com.jw.blog.wblog.entity.custom.ResultBean;
import com.jw.blog.wblog.service.IBlogTypeService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 无良芳
 * @since 2020-06-17
 */
@RestController

public class BlogTypeController {

    @Resource
    private IBlogTypeService iBlogTypeService;

    @PostMapping(value = "/selectBlogType")
    public ResultBean<List<BlogType>> selectBlogType(
            @RequestParam(value = "data", required = false) String data)
            throws Exception {
        Map<String, Object> map = new HashMap<>();
        if ("all".equals(data)) {
            map = null;
        }
        ResultBean<List<BlogType>> resultBean = new ResultBean<>();
        List<BlogType> blogTypes = iBlogTypeService.listByMap(map);
        if (blogTypes.size() == 0){
            resultBean.setCode(ResultBean.FAIL);
        }else {
            resultBean.setData(blogTypes);
        }
        return resultBean;
    }
}
